package com.example.anliku.service.serviceImpl;

import com.example.anliku.entity.Message;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.example.anliku.entity.Admin;
import com.example.anliku.mapper.AdminMapper;
import com.example.anliku.service.AdminService;

import java.util.Date;

@Service
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminMapper adminMapper;

    @Override
    public Message deleteByPrimaryKey(String adminId) {
        return adminMapper.deleteByPrimaryKey(adminId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public int insert(Admin record) {
        return adminMapper.insert(record);
    }

    @Override
    public Message insertSelective(Admin record) {
        Date nowdate = new Date();
        record.setAdminTime(nowdate);
        return adminMapper.insertSelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message selectByPrimaryKey(String adminId) {
        return Message.success(null).add(adminMapper.selectByPrimaryKey(adminId));
    }

    @Override
    public int updateByPrimaryKeySelective(Admin record) {
        return adminMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Admin record) {
        return adminMapper.updateByPrimaryKey(record);
    }

    @Override
    public Message selectAllByAdminIdAndAdminPwd(String updatedUserPwd, String userId) {
        Admin admin = adminMapper.selectAllByAdminIdAndAdminPwd(updatedUserPwd, userId);
        if (admin == null) {
            return Message.fail("帐号密码错误");
        } else {
            return Message.success(null).add(admin);
        }
    }

    @Override
    public Message updateAdminPwdByAdminId(String updatedAdminPwd, String adminId,String adminState) {
        return adminMapper.updateAdminPwdByAdminId(updatedAdminPwd, adminId,adminState) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message selectAll() {
        return Message.success(null).add(adminMapper.selectAll());
    }

}


